﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nature.Data.CkMarkup
{
    public partial class CkReactionSet
    {
        partial void OnInitialized()
        {
            foreach (var reaction in m_reactions)
            {
                reaction.ReactionSet = this;
            }            
        }

        public static object[] DefaultActivationEnergyUnits
        {
            get 
            {
                return new object[] { Nature.EnergyUnits.Calorie, Nature.MolarAmountUnits.Mole };
            }
        }

        public const Nature.EnergyUnits DefaultEnergyUnits = Nature.EnergyUnits.Calorie;
        public const Nature.MolarAmountUnits DefaultMolarAmountUnits = MolarAmountUnits.Mole;
        public const Nature.LengthUnits DefaultLengthUnits = LengthUnits.CentiMeter;
        public const Nature.TimeUnits DefaultTimeUnits = TimeUnits.Second;


        public object[] ActualActivationEnergyUnits
        {
            get 
            {
                if (false == this.ActivationEnergyUnits.HasValue)
                {
                    return CkReactionSet.DefaultActivationEnergyUnits;
                }
                switch (this.ActivationEnergyUnits.Value) 
                {
                    case(Nature.Data.CkMarkup.ActivationEnergyUnits.CalMole):
                        return new object[] { Nature.EnergyUnits.Calorie, Nature.MolarAmountUnits.Mole };
                    case (Nature.Data.CkMarkup.ActivationEnergyUnits.JouleMole):
                        return new object[] { Nature.EnergyUnits.Joule, Nature.MolarAmountUnits.Mole };
                    case (Nature.Data.CkMarkup.ActivationEnergyUnits.Kelvin):
                        return new object[] { Nature.TemperatureUnits.Kelvin };
                    case (Nature.Data.CkMarkup.ActivationEnergyUnits.KiloCalMole):
                        return new object[] { Nature.EnergyUnits.KiloCalorie, Nature.MolarAmountUnits.Mole };
                    default:
                        throw new NotSupportedException(this.ActivationEnergyUnits.Value.ToString());
                }
            }
        }

        

        public Nature.EnergyUnits ActualEnergyUnits
        {
            get 
            {
                return this.EnergyUnits.HasValue
                    ? Nature.Units.Parse<EnergyUnits>(this.EnergyUnits.Value.ToString())
                    : CkReactionSet.DefaultEnergyUnits;
            }
        }

        public Nature.MolarAmountUnits ActualMolarAmountUnits 
        {
            get 
            {
                return this.MolAmountUnits.HasValue
                    ? Nature.Units.Parse<Nature.MolarAmountUnits>(this.MolAmountUnits.Value.ToString())
                    : CkReactionSet.DefaultMolarAmountUnits;
            }
        }

        public Nature.LengthUnits ActualLengthUnits
        {
            get
            {
                return CkReactionSet.DefaultLengthUnits;
            }
        }

        public Nature.TimeUnits ActualTimeUnits
        {
            get
            {
                return CkReactionSet.DefaultTimeUnits;
            }
        }
    }
}
